﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Resources;
using System.Text;
using System.Windows.Forms;
using AiFrame.InterfaceLib.Plugins;
using AiFrame.InterfaceLib.Plugins.Events;
using AiFrame.InterfaceLib.Resources;
using AiFrame.InterfaceLib.Windows.Controls;
using AiFrameDemo.StartScreen.WinForms.Windows;

namespace AiFrameDemo.StartScreen.WinForms
{
    public class StartScreenPlugin: IPlugin, IConnectionReadyEvent
    {
        private ICoreInterface _ci;

        public void Load(ICoreInterface ci, string programPath)
        {
            _ci = ci;
            StartScreenRegistry.Instance.Initialize(ci, programPath);

            ResourceImages resourceImages = new ResourceImages();

            ResourceManager resourceManager = new ResourceManager("AiFrameDemo.StartScreen.WinForms.Properties.Resources", this.GetType().Assembly);

            IDataNavigationBar navigationBar = ci.NavigationBar.CreateDataNavigationBar();
            ci.NavigationBar.AddButton("navbarStartCenterBtn", "Information Center", "Startfenster", (Image) resourceManager.GetObject("startscreen"),
                                       navigationBar, OnStartCenterButtonClick);
            // Load actions here

            ToolStrip toolStrip = new ToolStrip();
            ToolStripButton copyButton = new ToolStripButton("Copy", resourceImages.Copy,
                delegate {SendKeys.Send("^C");});
            ToolStripButton cutButton = new ToolStripButton("Cut", resourceImages.Cut,
                delegate {SendKeys.Send("^X");});
            ToolStripButton pasteButton = new ToolStripButton("Paste", resourceImages.Paste,
                delegate { SendKeys.Send("^V"); });
            toolStrip.Items.Add(copyButton);
            toolStrip.Items.Add(cutButton);
            toolStrip.Items.Add(pasteButton);

            ci.ToolBarManager.AddToolGroup(toolStrip, true);
        }
        
        private void OnStartCenterButtonClick(object sender, EventArgs e)
        {
            ShowStartCenter();
        }

        public void Unload()
        {
            // Unload actions here
        }

        public string GetCaption()
        {
            return "Startscreen-Plugin";
        }

        public void OnConnectionReadyEvent()
        {
            ShowStartCenter();
        }

        private void ShowStartCenter()
        {
            if (!_ci.WindowManager.ExistsWindow<StartFrame>())
            {
                StartFrame startFrame = new StartFrame();
                _ci.WindowManager.RegisterWindow(startFrame);
            }
            else
                _ci.WindowManager.BringWindowToFront<StartFrame>();
        }
    }
}
